#include "GameMessage.hh"
#include "FleetAttackFleet.hh"
#include "FleetAttackPlanet.hh"
#include "FleetColonizePlanet.hh"
#include "FleetMove.hh"
#include "NextTurn.hh"
#include "PlanetAddTask.hh"
#include "PlanetDelTask.hh"
#include "StateChanged.hh"
#include "XmlServerThread.hh"
#include "../Exception.hh"

using namespace Network;

spGameMessage
GameMessage::construct(QDomElement const& message) {
    QDomElement inner = message.firstChildElement();
    QString tagName = inner.tagName();

    if (tagName == "next_turn")
        return NextTurn::construct(inner);

    if (tagName == "state_changed")
        return StateChanged::construct(inner);

    if (tagName == "fleet_attack_fleet")
        return FleetAttackFleet::construct(inner);

    if (tagName == "fleet_attack_planet")
        return FleetAttackPlanet::construct(inner);

    if (tagName == "fleet_move")
        return FleetMove::construct(inner);

    if (tagName == "fleet_colonize_planet")
        return FleetColonizePlanet::construct(inner);

    if (tagName == "planet_add_task")
        return PlanetAddTask::construct(inner);

    if (tagName == "planet_del_task")
        return PlanetDelTask::construct(inner);

    throw NonFatalProtocolError("game invalid");
}

